package com.luoboduner.moo.tool.ui.component.RTextSyntaxText;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.luoboduner.moo.tool.ui.component.textviewer.RegexRSyntaxTextViewer;
import com.luoboduner.moo.tool.ui.component.textviewer.RegexRTextScrollPane;
import com.luoboduner.moo.tool.util.ScrollUtil;
import com.luoboduner.moo.tool.util.UndoUtil;
import lombok.Getter;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;

import javax.swing.*;
import java.awt.*;
/**
 * 用于显示 对应的语法高亮
 *
 * @author Liutime
 */
@Getter
public class RTextSyntaxText {

  private JPanel contentPane;

  private JPanel mainPanel;

  private RegexRSyntaxTextViewer textArea;

  private RegexRTextScrollPane rTextScrollPane;

  public RTextSyntaxText(String contentType, String textInputValue) {
     /*
      设置语法高亮
     */
    textArea = new RegexRSyntaxTextViewer();
    switch (contentType) {
      case "XML" -> textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
      case "JSON" -> textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
      case "Java" -> textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
      case "SQL" -> textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
      case "HTML" -> textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML);
      case "JavaScript" -> textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
      case "CSS" -> textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CSS);
      case null, default -> textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    }
    rTextScrollPane = new RegexRTextScrollPane(textArea);
    mainPanel.add(rTextScrollPane, BorderLayout.CENTER);

    /*
    设置内容
     */
    textArea.setText(textInputValue);

    UndoUtil.register(textArea);
    ScrollUtil.smoothPane(rTextScrollPane);


  }

  public void init() {

  }

  {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
    $$$setupUI$$$();
  }

  /**
   * Method generated by IntelliJ IDEA GUI Designer
   * >>> IMPORTANT!! <<<
   * DO NOT edit this method OR call it in your code!
   *
   * @noinspection ALL
   */
  private void $$$setupUI$$$() {
    contentPane = new JPanel();
    contentPane.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
    final JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
    contentPane.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
    mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout(0, 0));
    panel1.add(mainPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
  }

  /**
   * @noinspection ALL
   */
  public JComponent $$$getRootComponent$$$() {
    return contentPane;
  }

}
